package cn.fintecher.pangolin.service.dataimp.model.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.Date;

/**
 * @Auther: xiaqun
 * @Description: 导出工单请求参数
 * @Date: 18:23 2019/10/18
 */

@Data
public class ExportWorkOrderRequest {
    @ApiModelProperty(value = "委托方ID")
    private String principalId;

    @ApiModelProperty(value = "模板ID")
    private String templateId;

    @ApiModelProperty(value = "最小工单日期")
    private Date minDate;

    @ApiModelProperty(value = "最大工单日期")
    private Date maxDate;

    public BoolQueryBuilder getBuilder() {
        BoolQueryBuilder builder = new BoolQueryBuilder();
        builder.must(QueryBuilders.matchPhraseQuery("principalId.keyword", this.principalId));
        builder.must(QueryBuilders.rangeQuery("findTime").gte(this.minDate.getTime()));
        builder.must(QueryBuilders.rangeQuery("findTime").lte(this.maxDate.getTime() + 86400000));
        return builder;
    }
}
